package com.iwords.android;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class GuideBeginIWords extends Activity {

	private void vibrate(){
		Vibrator mVibrator = (Vibrator)getApplication().getSystemService(android.app.Service.VIBRATOR_SERVICE);
		mVibrator.vibrate(new long[]{50,50},-1);
	}
	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_guide);
		WebView webView = (WebView)this.findViewById(R.id.user_guide_webview);
		webView.loadUrl("file:///android_asset/brief.html");  
		if(this.getIntent().getExtras()!=null && this.getIntent().getExtras().getBoolean("fromMenu")){
			Button neverShowAgain = (Button)this.findViewById(R.id.never_show_again);
			Button userGuideClose = (Button)this.findViewById(R.id.user_guide_close);
			userGuideClose.setVisibility(Button.GONE);
			neverShowAgain.setVisibility(Button.GONE);
		}
	}

	public void close(View view) {
		this.vibrate();
		Intent intent = new Intent(this, IWords.class);
		this.startActivity(intent);
	}

	public void neverShowAgain(View view) {
		this.vibrate();
		saveSettings(true);
		close(view);
	}

	private void saveSettings(boolean neverShowAgain) {
		SharedPreferences settings = this.getSharedPreferences(this.getClass()
				.getName(), MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("neverShowAgain", neverShowAgain);
		editor.commit();
	}
	

	public void onResume() {
		super.onResume(); 
		com.mobclick.android.MobclickAgent.onResume(this);
	}
	
	public void onPause() {
		super.onPause(); 
		com.mobclick.android.MobclickAgent.onPause(this);
		this.finish();
	}
}